#pragma once

#include "stdafx.h"

template<class Type>
class Manager
{
public:
	Manager<Type>* Instance()
	{
		if (_instance == NULL)
		{
			_instance = new Manager<Type>();
		}
		return _instance;
	}

	void add(Type* T)
	{
		manager.push_front(T);
	}

	void updata()
	{
		for (list<Type*>::iterator itor = manager.begin();
			itor != manager.end();)
		{
			if ((*itor)->checkRemove())
			{
				delete *itor;
				itor = manager.erase(itor);
			}else
			{
				(*itor)->updata();
				itor++;
			}
		}
	}

	void draw()
	{
		for (list<Type*>::iterator itor = manager.begin();
			itor != manager.end(); itor++)
		{
			(*itor)->draw();
		}
	}

	void clear()
	{
		for (list<Type*>::iterator itor = manager.begin();
			itor != manager.end(); itor++)
		{
			delete *itor;
		}
		list<Type*> t;
		manager.swap(t);
	}
protected:
	Manager()
	{
	}
private:
	list<Type*> manager;
	static Manager<Type>* _instance;
};

template<class Type>
Manager<Type>* Manager<Type>::_instance = NULL;